import { BaseEntity } from '@cool-midway/core';
import { Column, Entity, Index } from 'typeorm';

/**
 * 任务作业
 */
@Entity('task_job')
export class TaskJobEntity extends BaseEntity {
  @Index()
  @Column({ comment: '应用ID' })
  appId: number;

  @Column({ comment: '任务ID' })
  jobId: string;

  @Column({ comment: 'Topic' })
  topic: string;

  @Column({ comment: '名称' })
  name: string;

  @Column({ comment: 'cron', nullable: true })
  cron: string;

  @Column({
    comment: '时间间隔',
    nullable: true,
  })
  every: number;

  @Column({ comment: '类型 0-重复 1-延时', default: 0, type: 'tinyint' })
  type: number;

  @Column({ comment: '下一次执行时间', nullable: true })
  nextRunTime: Date;

  @Column({ comment: '延时时间', nullable: true })
  delay: number;

  @Column({ comment: '开始时间', type: 'datetime', nullable: true })
  startTime: Date;

  @Column({ comment: '状态 0-待执行 1-执行中 2-已完成 3-已停止', default: 0 })
  status: number;

  @Column({ comment: '备注', nullable: true })
  remark: string;

  @Column({ comment: '业务参数', type: 'json', nullable: true })
  body: any;
}
